// pages/onlyrefund/onlyrefund.js
let network = require("../../utils/network.js")
let app = getApp();
let url = app.globalData.url;
let discount = app.globalData.discount;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    out_trade_no:null,
    refund_type:2,
    inputValue:'', //退款原因
    orderDetail: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      discount: wx.getStorageSync('discount')
    })

    that.orderDetail(options.out_trade_no)

  },

  orderDetail(dh) {
    var that = this
    // 订单详情
    network.request({
      url: url + '/AppletsApi/Order/orderDetail.html',
      data: {
        applet_openid: wx.getStorageSync('applet_openid'),
        out_trade_no: dh,
      },
      method: 'post',
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        that.setData({
          orderDetail: res.data.data
        })
      }
    })
  },




  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  orderReturnGoods(out_trade_no,refundreply){
    network.request({
      url: url + '/AppletsApi/Order/orderReturnGoods.html',
      data: {
        applet_openid: wx.getStorageSync('applet_openid'),
        out_trade_no: out_trade_no, //订单号
        refundreply: refundreply,   //退货原因
        refund_type:2
      },
      method: 'post',
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res)
      }
    })
  },

  sunmit:function(e){
    var that = this
    that.orderReturnGoods(that.data.out_trade_no, that.data.inputValue)
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  imgload:function(){
    wx.chooseImage({
      count: 3,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths[0])
      }
    })
  }
})